﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal struct RgceLocRel
    {
        private ColRelNegU ColRelNegU;
        private ushort _rowIndex;

        public override string ToString()
        {
            return " _rowIndex " + _rowIndex + " colRelRegU " + ColRelNegU;
        }
        public RgceLocRel(ushort rowIndex, short columnIndex, bool isRelativeRow, bool isRelativeColumn)
        {
            this._rowIndex = rowIndex;
            this.ColRelNegU = new ColRelNegU(columnIndex, isRelativeRow, isRelativeColumn);
        }

        public ushort RowIndex
        {
            get { return _rowIndex; }
        }

        public bool IsRelativeRow
        {
            get { return this.ColRelNegU.rowRelative; }
        }

        public int ColumnIndex
        {
            get { return this.ColRelNegU.col; }
        }

        public bool IsRelativeColumn
        {
            get { return ColRelNegU.columnRelative; }
        }

        public bool IsAbsoluteRow
        {
            get { return !IsRelativeRow; }
        }

        public bool IsAbsoluteColumn
        {
            get { return !IsRelativeColumn; }
        }

        public ColRelNegU RawColumn
        {
            get { return this.ColRelNegU; }
        }

        public void Read(BinaryReader reader)
        {
            _rowIndex = reader.ReadUInt16();
            ColRelNegU.Read(reader);
        }

        public void Write(BinaryWriter writer)
        {
            writer.Write(_rowIndex);
            ColRelNegU.Write(writer);
        }
    }
}